<?php
/**
 * 配置管理
 */
namespace app\admins\controller\sys;
use \app\admins\controller\Auth;
class Config extends Auth{
    
    /**
     * 添加
     */
    public function index(){
        $ConfigManage = new \logic\sys\config\ConfigManage($this->getUser());
        $where = [
            'page'  => input('page'),
        ];
        $data = $ConfigManage->getAdminList($where);
        $showpage = showpage($data['total'],$data['page'],$data['limit']);
        $this->assign(get_defined_vars());
        return $this->fetch();
    }
    
    
    /**
     * 添加
     */
    public function add(){
        try{
            if( $_POST ){
                $param = array(
                    'type'      => input('type'),
                    'tag'       => input('tag'),
                    'name'      => input('name'),
                    'note'      => input('note'),
                    'content'   => input('content'),
                );
                $ConfigManage = new \logic\sys\config\ConfigManage($this->getUser());
                $ConfigManage->add($param);
                return $this->success('添加成功','/sys/config/index');
            }
            
            $this->assign(get_defined_vars());
            return $this->fetch();
        }catch(\think\Exception $e){
            $this->error($e->getMessage());
        }
    }
    
    
    /**
     * 编辑
     */
    public function edit(){        
        $id = input('id');
        if( $_POST ){
            $param = array(
                'type'      => input('type'),
                'tag'       => input('tag'),
                'name'      => input('name'),
                'note'      => input('note'),
                'content'   => input('content'),
            );
            $ConfigManage = new \logic\sys\config\ConfigManage($this->getUser());
            $ConfigManage->AdminEdit($id,$param);
            return $this->success('修改成功','/sys/config/index');
            exit;
        }
        $ConfigManage = new \logic\sys\config\ConfigManage($this->getUser());
        $info = $ConfigManage->find(['id'=>$id]);
        $this->assign(get_defined_vars());
        return $this->fetch();
    }
    
    /**
     * 编辑
     */
    public function show(){
        $this->assign(get_defined_vars());
        return $this->fetch();
    }
    
    
}